<template>
	<el-main>
		<el-card class="box-card" shadow="never">
			<div class="search-box">
				<el-button-group>
					<el-button :type="buttonType(0)" @click="checkTab(0)">全部</el-button>
					<el-button :type="buttonType(1)" @click="checkTab(1)">好评</el-button>
					<el-button :type="buttonType(2)" @click="checkTab(2)">中评</el-button>
					<el-button :type="buttonType(3)" @click="checkTab(3)">差评</el-button>
				</el-button-group>
				<el-form :inline="true" :model="searchForm" class="demo-form-inline" style="margin-top: 20px;">
					<el-form-item label="评论时间">
						<el-date-picker
							v-model="searchForm.create_time"
							type="daterange"
							value-format="YYYY-MM-DD"
							range-separator="至"
							start-placeholder="开始日期"
							end-placeholder="结束日期">
						</el-date-picker>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" @click="onSubmit" icon="el-icon-search">查询</el-button>
					</el-form-item>
				</el-form>
			</div>
			<div style="width:100%;height:0;border-bottom:#E4E7ED 1px dashed;margin-bottom: 10px"></div>
			<el-table
				:data="tableData"
				:row-style="{ height: '57px'}"
				style="width: 100%;font-size: 12px">
				<el-table-column
					prop="id"
					label="ID"
					width="75">
				</el-table-column>
				<el-table-column
					prop="goods_name"
					label="商品信息"
					width="300px">
				</el-table-column>
				<el-table-column
					prop="user_name"
					label="评论人">
				</el-table-column>
				<el-table-column
					prop="type"
					label="评论类型">
				</el-table-column>
				<el-table-column
					prop="desc_match"
					label="描述符合度">
				</el-table-column>
				<el-table-column
					prop="content"
					label="评论内容"
					width="300px">
				</el-table-column>
				<el-table-column
					prop="create_time"
					label="评论时间">
				</el-table-column>
				<el-table-column
					label="操作"
					fixed="right">
					<template #default="scope">
						<el-button @click="handleDel(scope.row)" type="text" size="small">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			<Pages :form="searchForm" :page-obj="page" @pageChange="pageChangeHandle" @pageJump="getList"></Pages>
		</el-card>
	</el-main>
</template>

<script>
import Pages from '@/components/pages'

export default {
	components: {
		Pages
	},
	data() {
		return {
			searchForm: {
				type: 0,
				create_time: '',
				page: 1,
				limit: 10
			},
			page: {
				total: 0
			},
			tableData: []
		}
	},
	mounted() {
		this.getList()
	},
	methods: {
		async getList() {
			let res = await this.$API.appraise.list.get(this.searchForm)
			this.tableData = res.data.data
			this.page.total = res.data.total
		},
		// 搜索
		onSubmit() {
			this.searchForm.page = 1
			this.getList()
		},
		// 删除
		handleDel(item) {
			this.$confirm('确定删除该评论？', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(async () => {
				let res = await this.$API.appraise.del.get({id: item.id})
				if (res.code == 0) {
					this.$message.success(res.msg)
					setTimeout(() => {
						this.getList()
					}, 500)
				} else {
					this.$message.error(res.msg)
				}
			}).catch(() => {});
		},
		// 选择状态
		checkTab(type) {
			this.searchForm.type = type
			this.getList()
		},
		// 翻页
		pageChangeHandle(page) {
			this.searchForm.page = page
			this.getList()
		},
		// 选择样式
		buttonType(type) {
			if (this.searchForm.type == type) {
				return 'primary'
			}
		}
	}
}
</script>

<style scoped>
.el-table__header tr,
.el-table__header th {
	padding: 0;
	height: 20px;
	line-height: 20px;
}

p {
	padding: 0;
	margin: 0;
}
.el-button--small {
	padding: 0 !important;
}
</style>
